package com.trt.eatmeat.util;

import com.trt.eatmeat.EatmeatApplication;
import com.trt.eatmeat.socket.MsgData;

import java.util.Map;

/**
 * @author mayufeng
 * @Title:
 * @Package
 * @Description:
 * @date 2022/2/311:46
 */
public class SocketWaitUtil {

    public Map<String,Object> waiting(MsgData data,int second){
        boolean flag =false;
        Long endTime = System.currentTimeMillis()+second*1000;
        while (!flag){
            if(System.currentTimeMillis() > endTime){
                flag=true;
            }else {
                flag= EatmeatApplication.resultMap.containsKey(data.get_reqNo());
            }
        }
        Object object= EatmeatApplication.resultMap.get(data.get_reqNo());
        if(object!=null){
            EatmeatApplication.resultMap.remove(data.get_reqNo());
        }
        return object==null?null:(Map<String,Object>)object;
    }
}
